package com.changeover.service.security;

import java.util.Collection;
import java.util.List;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import com.google.common.collect.ImmutableList;

public class UserAuthentication implements Authentication {
    private static final long serialVersionUID = -6823916440945427668L;

    private final List<GrantedAuthority> grantedAuthoritis;
    private final Authentication authentication;

    private boolean authenticated;

    public UserAuthentication(UserRole role, Authentication authentication) {
        GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role.name());
        this.grantedAuthoritis = ImmutableList.of(grantedAuthority);
        this.authentication = authentication;
    }

    public String getName() {
        return getClass().getSimpleName();
    }

    public Collection<? extends GrantedAuthority> getAuthorities() {
        return grantedAuthoritis;
    }

    public Object getCredentials() {
        return authentication.getCredentials();
    }

    public Object getDetails() {
        return authentication.getDetails();
    }

    public Object getPrincipal() {
        return authentication.getPrincipal();
    }

    public boolean isAuthenticated() {
        return authenticated;
    }

    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.authenticated = isAuthenticated;
    }

}
